package com.shr.leetcode;

/**
 * leetcode 566
 * @author sevn
 *
 */
public class ReshapeTheMatrix {
	
    public static int[][] matrixReshape(int[][] nums, int r, int c) {
    	if(r*c != nums.length * nums[0].length)
    		return nums;
    	else{
    		int[] array = new int[r*c];
    		int[][] newArray = new int[r][c];
    		int k = 0;
	        for(int i = 0;i<nums.length;i++){
	        	for(int j = 0;j<nums[i].length;j++){
	        		array[k++] = nums[i][j] ;
	        	}
	        }
	        
	        k = 0;
	        for(int i = 0;i<r;i++){
	        	for(int j = 0;j<c;j++){
	        		newArray[i][j] = array[k++] ;
	        	}
	        }
	        return newArray ;
    	}
    }
	
	public static void main(String[] args) {
		int[][] nums = {{2,3},{4,5}};
		int r = 1;
		int c = 3;
		int[][] results = matrixReshape(nums, r, c);
		System.out.println(results);
	}
}
